package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.YlMessageControl;
import com.ruoyi.system.service.IYlMessageControlService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 消息公告管理Controller
 * 
 * @author ruoyi
 * @date 2022-02-18
 */
@RestController
@RequestMapping("/message")
public class YlMessageControlController extends BaseController
{
    @Autowired
    private IYlMessageControlService ylMessageControlService;

    /**
     * 查询消息公告管理列表
     */
    @RequiresPermissions("ylsystem:message:list")
    @GetMapping("/list")
    public TableDataInfo list(YlMessageControl ylMessageControl)
    {
        startPage();
        List<YlMessageControl> list = ylMessageControlService.selectYlMessageControlList(ylMessageControl);
        return getDataTable(list);
    }

    /**
     * 导出消息公告管理列表
     */
    @RequiresPermissions("ylsystem:message:export")
    @Log(title = "消息公告管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlMessageControl ylMessageControl)
    {
        List<YlMessageControl> list = ylMessageControlService.selectYlMessageControlList(ylMessageControl);
        ExcelUtil<YlMessageControl> util = new ExcelUtil<YlMessageControl>(YlMessageControl.class);
        util.exportExcel(response, list, "消息公告管理数据");
    }

    /**
     * 获取消息公告管理详细信息
     */
    @RequiresPermissions("ylsystem:message:query")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return AjaxResult.success(ylMessageControlService.selectYlMessageControlByMessageId(messageId));
    }

    /**
     * 新增消息公告管理
     */
    @RequiresPermissions("ylsystem:message:add")
    @Log(title = "消息公告管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlMessageControl ylMessageControl)
    {
        return toAjax(ylMessageControlService.insertYlMessageControl(ylMessageControl));
    }

    /**
     * 修改消息公告管理
     */
    @RequiresPermissions("ylsystem:message:edit")
    @Log(title = "消息公告管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlMessageControl ylMessageControl)
    {
        return toAjax(ylMessageControlService.updateYlMessageControl(ylMessageControl));
    }

    /**
     * 删除消息公告管理
     */
    @RequiresPermissions("ylsystem:message:remove")
    @Log(title = "消息公告管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(ylMessageControlService.deleteYlMessageControlByMessageIds(messageIds));
    }
}
